<template>
  <div class="page-container news-container">
    <!-- Banner组件 -->
    <page-banner
      title="新闻中心"
      description="了解公司最新动态和行业资讯"
      background-image="/images/news-banner.jpg"
    />
    
    <!-- 搜索组件 -->
    <div class="search-section">
      <news-search
        @search="handleSearch"
        @category-change="handleCategoryChange"
      />
    </div>

    <!-- 新闻列表组件 -->
    <div class="list-section">
      <news-list
        ref="newsListRef"
        :search-keyword="searchKeyword"
        :category="selectedCategory"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import PageBanner from '@/components/PageBanner.vue'
import NewsSearch from './components/NewsSearch.vue'
import NewsList from './components/NewsList.vue'

const newsListRef = ref(null)
const searchKeyword = ref('')
const selectedCategory = ref('')

// 处理搜索
const handleSearch = (keyword) => {
  searchKeyword.value = keyword?.trim() || ''
  if (newsListRef.value) {
    newsListRef.value.fetchNewsList()
  }
}

// 处理分类变化
const handleCategoryChange = (category) => {
  selectedCategory.value = category || ''
  if (newsListRef.value) {
    newsListRef.value.fetchNewsList()
  }
}
</script>

<style lang="scss" scoped>
.news-container {
  padding: 0 0 80px;
  background: #f8f9fa;
  min-height: 100vh;
  
  .section-header {
    text-align: center;
    margin-bottom: 60px;
    
    .section-title {
      font-size: 36px;
      font-weight: 700;
      color: #2c3e50;
      margin-bottom: 20px;
      position: relative;
      display: inline-block;
      
      &::after {
        content: '';
        position: absolute;
        bottom: -10px;
        left: 50%;
        transform: translateX(-50%);
        width: 80px;
        height: 4px;
        background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
        border-radius: 2px;
      }
    }
    
    .section-desc {
      font-size: 16px;
      color: #606266;
      max-width: 600px;
      margin: 0 auto;
      line-height: 1.6;
    }
  }

  .search-section {
    max-width: 800px;
    margin: 0 auto 40px;
    padding: 0 20px;
  }

  .list-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    
    :deep(.el-table) {
      background: transparent;
      
      &::before {
        display: none;
      }
      
      .el-table__header-wrapper {
        th {
          background: #f8f9fa;
          font-weight: 600;
          color: #2c3e50;
          padding: 16px 0;
        }
      }
      
      .el-table__row {
        transition: all 0.3s ease;
        
        &:hover {
          background: #f8f9fa;
          transform: translateY(-2px);
        }
        
        td {
          padding: 20px 0;
          border-bottom: 1px solid #eee;
        }
      }
    }
  }
  
  @media (max-width: 768px) {
    padding: 0 0 60px;
    
    .section-header {
      margin-bottom: 40px;
      
      .section-title {
        font-size: 28px;
      }
      
      .section-desc {
        font-size: 14px;
        padding: 0 20px;
      }
    }
    
    .search-section {
      margin-bottom: 30px;
    }
  }
}
</style>
